package com.ctsi.ftp.util;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;

import java.io.File;
import java.io.FileFilter;

/**
 * 过滤文件后缀，过滤后缀为filePostfix形式的文件
 * @author ye
 *
 */
public class FilePostFixFilter implements FileFilter{
	
	private String filePostfix ;

	public FilePostFixFilter(){
		super();
	}
	
	public FilePostFixFilter(String filePostfix){
		this.filePostfix = filePostfix;
	}
	
	public boolean accept(File pathname) {
		if (pathname.isFile()) {
			String fileName = pathname.getName();
			if (filePostfix != null) {
				if (!filePostfix.equals(".*")) {
					if (!fileName.endsWith(filePostfix)) {
						return false;
					}
				}
			}
			return true;
		}
		return false;
	}

}
